from selenium import webdriver
import datetime
from movieSpider import movieSpider


class movieMsgSpider:
    def start(begin_y,begin_m,begin_d,end_y,end_m,end_d):
        ##### 初始化Spider（连接数据库，连接百度Ocr）
        mySpider = movieSpider()
        #创建driver，模拟浏览器
        options = webdriver.ChromeOptions()
        options.add_argument('--headless')
        options.add_argument('blink-settings=imagesEnabled=false')
        driver = webdriver.Chrome(executable_path='/Users/aaa/py/chromedriver',options=options)

        options2 = webdriver.ChromeOptions()
        driver2 = webdriver.Chrome(executable_path='/Users/aaa/py/chromedriver',options= options2)
        #日期遍历
        begin = datetime.date(begin_y,begin_m,begin_d)
        end = datetime.date(end_y,end_m,end_d)
        delta = datetime.timedelta(days=1)
        #开始遍历
        while begin < end:
            date = begin.strftime("%Y-%m-%d")
            begin += delta
            mySpider.getMovieDataByDate(driver=driver,date=date,driver2=driver2)
        #退出模拟器
        driver2.quit()
        driver.quit()


    if __name__ == '__main__':
        start(2020,7,20,2021,6,25)